package com.corona.game;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.Vector2;
import com.corona.Game;
import com.corona.game.util.TextureCache;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

/* compiled from: Player.java */
/* loaded from: pokewilds.jar:com/pkmngen/game/SelectAmount.class */
public class SelectAmount extends Menu {
    Sprite textbox;
    Player.Craft craft;
    Action prevAction;
    boolean isMenu;
    public Action.Layer layer = Action.Layer.gui_105;
    public int amount = 0;
    int maxAmount = 1;

    public SelectAmount(Player.Craft craft, Action prevAction, Action nextAction) {
        this.isMenu = false;
        this.craft = craft;
        this.prevAction = prevAction;
        if (this.prevAction != null && (this.prevAction instanceof Menu)) {
            this.isMenu = true;
        }
        this.textbox = new Sprite(TextureCache.get(Gdx.files.internal("amount_bg1.png")), 0, 0, 160, 144);
        this.nextAction = nextAction;
    }

    @Override // com.corona.game.Action
    public String getCamera() {
        return "gui";
    }

    @Override // com.corona.game.Action
    public Action.Layer getLayer() {
        return this.layer;
    }

    @Override // com.corona.game.Action
    public void firstStep(Game game) {
        this.amount = 1;
    }

    @Override // com.corona.game.Action
    public void step(Game game) {
        if (this.isMenu) {
            this.prevAction.step(game);
        }
        this.textbox.draw(game.uiBatch);
        if (!this.disabled) {
            if (InputProcessor.upJustPressed) {
                if (game.player.hasCraftRequirements(this.craft, this.amount + 1)) {
                    this.amount++;
                }
            } else if (InputProcessor.downJustPressed) {
                if (this.amount > 1) {
                    this.amount--;
                }
            } else if (InputProcessor.rightJustPressed) {
                for (int i = 0; i < 10; i++) {
                    if (game.player.hasCraftRequirements(this.craft, this.amount + 1)) {
                        this.amount++;
                    }
                }
            } else if (InputProcessor.leftJustPressed) {
                this.amount -= 10;
                if (this.amount <= 1) {
                    this.amount = 1;
                }
            }
            String word = "";
            if (this.amount <= 99) {
                word = word + "x";
            }
            String word2 = word + String.format(Locale.ROOT, "%02d", Integer.valueOf(this.amount));
            for (int i2 = 0; i2 < word2.length(); i2++) {
                game.uiBatch.draw(game.textDict.get(Character.valueOf(word2.charAt(i2))), (float) (130 + (8 * i2)), 56.0f);
            }
            if (InputProcessor.aJustPressed) {
                this.disabled = true;
                this.craft.amount = this.amount;
                game.actionStack.remove(this);
                game.insertAction(new Selected(this.craft, this, this.nextAction));
            } else if (InputProcessor.bJustPressed) {
                game.insertAction(new PlayMusic("click1", (Action) null));
                game.actionStack.remove(this);
                if (this.isMenu) {
                    ((Menu) this.prevAction).disabled = false;
                }
                game.insertAction(this.prevAction);
            }
        }
    }

    /* compiled from: Player.java */
    /* loaded from: pokewilds.jar:com/pkmngen/game/SelectAmount$Selected.class */
    class Selected extends Menu {
        Sprite arrow;
        Sprite arrowWhite;
        Sprite textBoxTop;
        Sprite textBoxMiddle;
        Sprite textBoxBottom;
        Map<Integer, Vector2> getCoords;
        int curr;
        Vector2 newPos;
        Sprite helperSprite;
        ArrayList<String> words;
        Player.Craft craft;
        Action prevAction;
        boolean isMenu;
        public Action.Layer layer = Action.Layer.gui_104;
        int textboxDelay = 0;

        public Selected(Player.Craft craft, Action prevAction, Action nextAction) {
            SelectAmount.this = this$0;
            this.isMenu = false;
            this.craft = craft;
            this.prevAction = prevAction;
            if (prevAction != null && (prevAction instanceof Menu)) {
                this.isMenu = true;
            }
            this.nextAction = nextAction;
            this.getCoords = new HashMap();
            this.words = new ArrayList<>();
            this.words.add("USE");
            this.words.add("CANCEL");
            this.getCoords.put(0, new Vector2(97.0f, 56.0f));
            this.getCoords.put(1, new Vector2(97.0f, 40.0f));
            this.arrow = new Sprite(TextureCache.get(Gdx.files.internal("battle/arrow_right1.png")), 0, 0, 5, 7);
            this.arrowWhite = new Sprite(TextureCache.get(Gdx.files.internal("battle/arrow_right_white.png")), 0, 0, 5, 7);
            this.textBoxTop = new Sprite(TextureCache.get(Gdx.files.internal("menu/selected_menu_top.png")), 0, 0, 71, 19);
            this.textBoxMiddle = new Sprite(TextureCache.get(Gdx.files.internal("menu/selected_menu_middle.png")), 0, 0, 71, 16);
            this.textBoxBottom = new Sprite(TextureCache.get(Gdx.files.internal("menu/selected_menu_bottom.png")), 0, 0, 71, 19);
            this.newPos = this.getCoords.get(0);
            this.arrow.setPosition(this.newPos.x, this.newPos.y);
            this.curr = 0;
        }

        @Override // com.corona.game.Action
        public String getCamera() {
            return "gui";
        }

        @Override // com.corona.game.Action
        public Action.Layer getLayer() {
            return this.layer;
        }

        @Override // com.corona.game.Action
        public void step(Game game) {
            if (this.isMenu) {
                this.prevAction.step(game);
            }
            if (this.textboxDelay < 1) {
                this.textboxDelay++;
                return;
            }
            for (int i = 0; i < this.words.size(); i++) {
                if (i == 0) {
                    game.uiBatch.draw(this.textBoxTop, 89.0f, (float) (68 + (16 * (this.words.size() - 3))));
                } else if (i == this.words.size() - 1) {
                    game.uiBatch.draw(this.textBoxBottom, 89.0f, 33.0f);
                } else {
                    game.uiBatch.draw(this.textBoxMiddle, 89.0f, (float) (52 + (16 * ((this.words.size() - i) - 2))));
                }
                String word = this.words.get(i);
                for (int j = 0; j < word.length(); j++) {
                    game.uiBatch.draw(game.textDict.get(Character.valueOf(word.charAt(j))), (float) (104 + (8 * j)), (float) (72 - (16 * ((i - this.words.size()) + 3))));
                }
            }
            this.arrowWhite.setPosition(this.newPos.x, this.newPos.y);
            this.arrowWhite.draw(game.uiBatch);
            if (!this.disabled) {
                this.arrow.setPosition(this.newPos.x, this.newPos.y);
                game.uiBatch.draw(this.arrow, this.arrow.getX(), this.arrow.getY());
                if (InputProcessor.upJustPressed) {
                    if (this.curr > 0) {
                        this.curr--;
                        this.newPos = this.getCoords.get(Integer.valueOf(this.curr));
                    }
                } else if (InputProcessor.downJustPressed && this.curr < this.words.size() - 1) {
                    this.curr++;
                    this.newPos = this.getCoords.get(Integer.valueOf(this.curr));
                }
                if (InputProcessor.aJustPressed) {
                    String word2 = this.words.get(this.curr);
                    if ("CANCEL".equals(word2)) {
                        game.insertAction(new PlayMusic("click1", (Action) null));
                        game.actionStack.remove(this);
                        if (this.isMenu) {
                            ((Menu) this.prevAction).disabled = false;
                        }
                        game.insertAction(this.prevAction);
                    } else if ("USE".equals(word2)) {
                        game.actionStack.remove(this);
                        game.insertAction(this.nextAction);
                    }
                } else if (InputProcessor.bJustPressed) {
                    game.insertAction(new PlayMusic("click1", (Action) null));
                    game.actionStack.remove(this);
                    if (this.isMenu) {
                        ((Menu) this.prevAction).disabled = false;
                    }
                    game.insertAction(this.prevAction);
                }
            }
        }
    }
}
